<template>
    <!-- 提现记录 -->
    <div class="app-container">
        <el-card>
            <el-form size="mini" ref="searchForm" :model="searchForm" inline>
                <el-form-item label="用户ID/手机号">
                    <el-input v-model="searchForm.account" placeholder="请输入用户ID/手机号"></el-input>
                </el-form-item>
                <el-form-item label="用户昵称">
                    <el-input v-model="searchForm.nickname" placeholder="请输入昵称"></el-input>
                </el-form-item>
                <el-form-item label="查询时间：" prop="beginTime">
                    <el-date-picker style="width: 200px" v-model="searchForm.beginTime" align="right" type="date"
                        placeholder="选择开始日期" :picker-options="$pickerDateOptions" value-format="yyyy-MM-dd"
                        format="yyyy 年 MM 月 dd 日">
                    </el-date-picker>
                </el-form-item>
                <el-form-item>-</el-form-item>
                <el-form-item prop="endTime">
                    <el-date-picker style="width: 200px" v-model="searchForm.endTime" align="right" type="date"
                        placeholder="选择结束日期" :picker-options="$pickerDateOptions" value-format="yyyy-MM-dd"
                        format="yyyy 年 MM 月 dd 日">
                    </el-date-picker>
                </el-form-item>
                <el-form-item>
                    <el-button icon="el-icon-refresh" @click="resetForm('searchForm')">重置</el-button>
                    <el-button icon="el-icon-search" type="primary" @click="handleSearchList()">查询</el-button>
                </el-form-item>
            </el-form>

            <el-table v-loading="listLoading" :data="tableData.data" border stripe size="mini">
                <el-table-column align="center" label="序号" type="index" width="80"></el-table-column>
                <el-table-column align="center" label="用户ID" prop="memberId"></el-table-column>
                <el-table-column align="center" label="用户昵称" prop="memberNickname"></el-table-column>
                <el-table-column align="center" label="用户手机号" prop="telephone"></el-table-column>
                <el-table-column align="center" label="提现金额" prop="price">
                     <template slot-scope="scope">
                       {{scope.row.price / 100}}元
                    </template>
                </el-table-column>
                <el-table-column align="center" label="提现时间" prop="createTime"></el-table-column>
                <el-table-column align="center" label="提现状态" prop="status">
                    <template slot-scope="scope">
                        <!-- 状态：0-审核中；10-审核通过；20-审核不通过；预留：11-提现成功；21-提现失败 -->
                        <el-tag size="mini" v-if="scope.row.status == 0" type="info">审核中</el-tag>
                        <el-tag size="mini" v-if="scope.row.status == 10" type="success">审核通过</el-tag>
                        <el-tag size="mini" v-if="scope.row.status == 20" type="danger">审核不通过</el-tag>
                        <el-tag size="mini" v-if="scope.row.status == 11" type="success">提现成功</el-tag>
                        <el-tag size="mini" v-if="scope.row.status == 21" type="danger">提现失败</el-tag>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="操作" width="200">
                    <template slot-scope="scope">
                        <el-button size="mini" type="text"  :disabled="scope.row.status != 0"  @click="referPrice(scope.row)">审核</el-button>
                        <el-button size="mini" type="text" :disabled="scope.row.status != 0" @click="rejectPrice(scope.row)">驳回</el-button>
                    </template>
                </el-table-column>

            </el-table>
            <el-pagination class="pageRight" background layout="total, sizes, prev, pager, next, jumper"
                :page-sizes="[10, 20, 50, 100]" :page-size="searchForm.pageSize" :total="tableData.total"
                @size-change="handleSizeChange" @current-change="handleCurrentChange"></el-pagination>
        </el-card>
    </div>
</template>

<script>
import { getBrokerageWithdrawPage, passBrokerageWithdraw, rejectBrokerageWithdraw } from "@/api/brokerage.js"
export default {
    data() {
        return {
            searchForm: {
                account: '',
                nickname: '',
                beginTime: '',
                endTime: '',
                pageNum: 1,
                pageSize: 10
            },
            listLoading: false,
            tableData: {
                data: [],
                total: 0
            }
        };
    },
    created() {
        this.getList();
    },
    methods: {
        referPrice(v) {
            this.$confirm(`请确认是否通过用户  ${v.price / 100}元 提现审核`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                passBrokerageWithdraw(v.id).then(res => {
                    this.$message.success('操作成功');
                    this.getList();
                })
            })
        },
        rejectPrice(v) {
            this.$prompt('请输入拒绝原因', '提示', {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                inputErrorMessage: "请输入拒绝原因",
                inputType: "textarea",
                inputPlaceholder: "请输入拒绝原因",
                inputValidator: value => {
                    if (!value) return "输入不能为空";
                }
            }).then(({ value }) => {
                let params = {
                    id: v.id,
                    auditReason: value
                }
                rejectBrokerageWithdraw(params).then(res=> {
                    this.$message.success('操作成功');
                    this.getList()
                })
            }).catch(() => {

            });
        },

        resetForm() {
            this.searchForm= {
                account: '',
                nickname: '',
                beginTime: '',
                endTime: '',
                pageNum: 1,
                pageSize: 10
            }
            this.getList()
        },
        handleSearchList() {
            this.searchForm.pageNum = 1;
            this.getList();
        },
        getList() {
            this.listLoading = true;
            getBrokerageWithdrawPage(this.searchForm).then(res => {
                this.tableData.data = res.data.list
                this.tableData.total = res.data.total
            }).finally(v => {
                this.listLoading = false
            });
        },
        handleSizeChange(val) {
            this.searchForm.pageSize = val
            this.getList()
        },
        handleCurrentChange(val) {
            this.searchForm.pageNum = val
            this.getList()
        },
    },
}
</script>

<style></style>